<?php

require_once '../config.php';

require_once '../includes/functions.php';

if (!isLoggedIn()) {

    redirect('../login.php');

}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {

    $apps = getApps();

    $newApp = [

        'id' => uniqid(),

        'name' => $_POST['name'],

        'icon' => $_POST['icon'],

        'download_url' => $_POST['download_url'],

        'description' => $_POST['description'],

        'update_content' => $_POST['update_content'],

        'version' => $_POST['version'],

        'create_time' => date('Y-m-d H:i:s')

    ];

    

    $apps[] = $newApp;

    saveApps($apps);

    

    redirect('../admin.php');

} else {

    redirect('../admin.php');

}

?>